<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
  <head>
    <th:block th:include="include :: header('修改学习材料')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
  </head>
  <body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
      <form
        class="form-horizontal m"
        id="form-xxcl-edit"
        th:object="${djStudyMaterial}"
      >
        <input name="id" th:field="*{id}" type="hidden" />
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label is-required">资料标题：</label>
            <div class="col-sm-8">
              <input
                name="title"
                th:field="*{title}"
                class="form-control"
                type="text"
                required
              />
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label">内容分类：</label>
            <div class="col-sm-8">
              <select
                name="category"
                class="form-control"
                id="category"
                required
              >
                <option value="ZDWX">重点文献</option>
                <option value="XXFD">学习辅导</option>
                <option value="ZCWJ">政策文件</option>
                <option value="XDTH">心得体会</option>
              </select>
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label">是否启用：</label>
            <div class="col-sm-8">
              <input
                name="status"
                type="radio"
                th:value="0"
                th:field="*{status}"
              />
              <label>不启用</label>
              <input
                name="status"
                type="radio"
                th:value="1"
                th:field="*{status}"
              />
              <label>启用</label>
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label">内容类型：</label>
            <div class="col-sm-8">
              <select name="contentType" class="form-control" id="contentType">
                <option value="pdf">PDF文件</option>
                <option value="doc">DOC文件</option>
              </select>
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label">描述信息：</label>
            <div class="col-sm-8">
              <input
                name="info"
                th:field="*{info}"
                class="form-control"
                type="text"
              />
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label is-required">资料内容：</label>
            <div class="col-sm-8">
              <input type="hidden" name="contentUrl" th:field="*{contentUrl}" />
              <div class="file-loading">
                <input
                  class="form-control file-upload"
                  id="contentUrl"
                  name="file"
                  type="file"
                />
              </div>
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label">发布时间：</label>
            <div class="col-sm-8">
              <div class="input-group date">
                <input
                  name="publishTime"
                  th:value="${#dates.format(djStudyMaterial.publishTime, 'yyyy-MM-dd')}"
                  class="form-control"
                  placeholder="yyyy-MM-dd"
                  type="text"
                />
                <span class="input-group-addon"
                  ><i class="fa fa-calendar"></i
                ></span>
              </div>
            </div>
          </div>
        </div>
        <div class="col-xs-12">
          <div class="form-group">
            <label class="col-sm-3 control-label">阅读次数：</label>
            <div class="col-sm-8">
              <input
                name="readCount"
                th:field="*{readCount}"
                class="form-control"
                type="text"
              />
            </div>
          </div>
        </div>
      </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
      var prefix = ctx + "learn/xxcl";
      $("#form-xxcl-edit").validate({
        focusCleanup: true,
      });

      function submitHandler() {
        if ($.validate.form()) {
          $.operate.save(prefix + "/edit", $("#form-xxcl-edit").serialize());
        }
      }

      $("input[name='publishTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true,
      });

      $(".file-upload").each(function (i) {
        var val = $("input[name='" + this.id + "']").val();
        $(this)
          .fileinput({
            uploadUrl: ctx + "common/upload",
            initialPreviewAsData: true,
            initialPreview: [val],
            maxFileCount: 1,
            autoReplace: true,
          })
          .on("fileuploaded", function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(
              data.response.fileName
            );
          })
          .on("fileremoved", function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val("");
          });
        $(this).fileinput("_initFileActions");
      });
    </script>
  </body>
</html>
